//
//  Array+Extension.swift
//  HZJTreeView
//
//  Created by 何治军 on 2020/6/18.
//  Copyright © 2020 何治军. All rights reserved.
//

//MARK: - 对Array进行扩展
extension Array where Element == HZJTreeViewModelProtocol {
    func getTreeData() -> [HZJTreeViewModelProtocol] {
        var result:[HZJTreeViewModelProtocol] = []
        for item in self {
            result.append(item)
            result.append(contentsOf: item.getAllChildModel())
        }
        return result
    }
    
    func getAllShowTreeData() -> [HZJTreeViewModelProtocol] {
        var result:[HZJTreeViewModelProtocol] = []
        for item in self {
            if item.isShowCurrent {
                result.append(item)
            }
            if item.isOpen {
                result.append(contentsOf: item.getAllShowChildModel())
            }
        }
        return result
    }
}
